<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/6 0006
 * Time: 17:45
 */

namespace app\index\controller;


use think\Controller;

class Cosplay extends Controller
{
    public function index(){
        $m_id = session('member_id');
        if(!empty($m_id)){
            $member = db('member')->where('id',$m_id)->find();
            $this->assign('member', $member);
        }
        $recommend = $this->recommend();
//        dump($recommend);die;
        //新书榜
        $newBook = $this->newBook();
        $footer = $this->footer();
        $banner = $this->banner();
        $this->assign([
            'current' => 'cosplay',
            'recommend' => $recommend,
            'newBook' => $newBook,
            'footer' => $footer,
            'banner' => $banner
        ]);
        return view("index");
    }
    //主编推荐
    public function recommend(){
        $data = model('cosplay')
            ->cache(true,360)
            ->where('recommend','1')
            ->order('update','desc')
            ->with('book')
            ->limit(20)
            ->select();
        return $data;
    }
    //新书榜
    public function newBook(){
        $data = model('cosplay')
            ->cache(true,360)
            ->where('new_book','1')
            ->order('update','desc')
            ->with('book')
            ->limit(10)
            ->select();
        return $data;
    }
    public function footer(){
        $data = db("web") ->cache(true,600)->find();
        return $data;
    }
    //轮播
    public function banner(){
        //state == 3 的时候 轮播图为小说专区
        $banner = db("banner")
            ->where('state',3)
            ->cache(true,60)
            ->order('id', 'desc')
            ->limit(3)
            ->select();
        return $banner;
    }
}